﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Win32;
using System.IO;
using System.Text.Json.Nodes;
using System.Text.Json;
using System.Windows;
using XYAC.Framework.MonitorTireMaterialManual.DataExporter;
using XYAC.Framework.MonitorTireMaterialManual.Entities;
using XYAC.Framework.MonitorTireMaterialManual.Extensions;
using XYAC.Framework.MonitorTireMaterialManual.IServices;
using System.Text;
using XYAC.Framework.MonitorTireMaterialManual.LocalData.Models;
using XYAC.Framework.MonitorTireMaterialManual.Converters;
using System.Windows.Media;
using XYAC.Framework.MonitorTireMaterialManual.common;
using System.Windows.Markup;

namespace XYAC.Framework.MonitorTireMaterialManual.ViewModels
{
    /// <summary>
    /// 胎面离线扫描检查表（半钢）
    /// </summary>
    public partial class SemiSteelTreadScanViewModel : ViewModelBase
    {

        /// <summary>
        /// 临时数据交换目录。
        /// 保存用户选择的最近一次的数据目录。
        /// 重启软件会丢失此目录而采用固定的初始目录。
        /// </summary>
        static string tempDataSwapFolder = "";
        /// <summary>
        /// 主观判断 是 不是
        /// </summary>
        private List<Item> mindCheck;
        public List<Item> MindCheckList
        {
            get => mindCheck;
            set => SetProperty(ref mindCheck, value);
        }
        private List<Item> mindCheck1;
        public List<Item> MindCheckList1
        {
            get => mindCheck1;
            set => SetProperty(ref mindCheck1, value);
        }
        /// <summary>
        /// 班次清单
        /// </summary>
        private List<Item> shiftList;
        public List<Item> ShiftList
        {
            get => shiftList;
            set => SetProperty(ref shiftList, value);
        }
        /// <summary>
        /// 主观判断 合格 还是不合格
        /// </summary>
        private List<Item> mindPassList;
        public List<Item> MindPassList
        {
            get => mindPassList;
            set => SetProperty(ref mindPassList, value);
        }

        public static string TempDataSwapFolder
        {
            get => tempDataSwapFolder;
            set => tempDataSwapFolder = value;
        }
        public QualityDataUploadViewModel? UploadViewModel { get; set; }

        public SemiSteelTreadScanViewModel(IOptionsMonitor<AppConfig> options,
            ILogger<QualityDataHistoryViewModel> logger, IServiceProvider provider)
        {
            this.AppConfig = options;
            this.Logger = logger;
            this.provider = provider;
            UploadViewModel = this.provider.GetService<QualityDataUploadViewModel>();
            this.UserId = this.AppConfig.CurrentValue.UserId.Trim();
            this.CurrentShift = this.AppConfig.CurrentValue.CurrentShift;

            ScanDatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            MindCheckList = new List<Item>();
            MindCheckList.Add(new Item("√", "True"));
            MindCheckList.Add(new Item("×", "False"));

            MindCheckList1 = new List<Item>();
            MindCheckList1.Add(new Item("NULL", "NULL"));
            MindCheckList1.Add(new Item("√", "True"));
            MindCheckList1.Add(new Item("×", "False"));
            //LoadCurrentSelectionSpecInfo();

            ShiftList = new List<Item>();
            ShiftList.Add(new Item("早班", "早"));
            ShiftList.Add(new Item("夜班", "夜"));

            MindPassList = new List<Item>();
            MindPassList.Add(new Item("合格", "True"));
            MindPassList.Add(new Item("不合格", "False"));
        }

        [ObservableProperty]
        private DataFile _dataFile;

        public IOptionsMonitor<AppConfig> AppConfig { get; }
        public ILogger Logger { get; }
        public Action CloseWindow { get; internal set; }

        [ObservableProperty]
        private SemiSteelTreadScanReport _semiSteelTreadScanReport;
        [ObservableProperty]
        private string _scanDatetime;

        private IServiceProvider provider;
        bool maySave=false;
        /// <summary>
        /// 打开txt报表数据
        /// </summary>
        [RelayCommand]
        private void OpenReportData1()
        {
            try
            {
                if (!isPrecheck())
                {
                    MessageBox.Show("请先执行本班次今日的班前检点！", "应用提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                string tempDir = TempDataSwapFolder;
                if (string.IsNullOrEmpty(tempDir))
                    tempDir = this.AppConfig.CurrentValue.Folder1Path;
                // 创建并配置 OpenFileDialog 对象
                var openFileDialog = new OpenFileDialog
                {
                    InitialDirectory = tempDir,
                    Title = "Open Text File",
                    Filter = "文本文件 (*.txt)|*.txt",
                    Multiselect = false
                };
                List<string> errors = null;
                // 显示文件选择对话框
                if (openFileDialog.ShowDialog() == true)
                {
                    string fileName = openFileDialog.FileName;
                    FileInfo fileInfo = new FileInfo(fileName);
                    TempDataSwapFolder = fileInfo.DirectoryName;

                    this.AppConfig.CurrentValue.Folder1Path = TempDataSwapFolder;
                    SaveNewJsonConfig();

                    // 加载并解析数据文件
                    this.DataFile = DataFileParser.LoadFromFile(fileName);

                    if (DataFile.Validate(out errors))
                    {
                        maySave = true;
                        //var IxReferenceStablePoint = DataFile.StableKeys.OrderBy(T => Math.Abs(T.Coordinate - DataFile.XReference)).FirstOrDefault();
                        //var IxReferencePointIndex = DataFile.StableKeys.IndexOf(IxReferenceStablePoint);
                        //var IxReferenceMeasurePoint = DataFile.MeasureKeys[IxReferencePointIndex];

                        //验证成功,赋值给本地视图模型
                        this.SemiSteelTreadScanReport = new()
                        {
                            PlanId = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SERIAL_NUMBER,
                            Shift = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SHIFT,
                            SerialNumber = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SERIAL_NUMBER,
                            ScanedDatetime = ScanDatetime,  //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            SpecNameInfact = UploadViewModel.CurrentUserChoicePlan?.InspectModel.PART_NUMBER,
                            PlanDate = UploadViewModel.CurrentUserChoicePlan.InspectModel.PLAN_DATE.Value,
                            Eqp = UploadViewModel.CurrentUserChoicePlan?.InspectModel.EQP,

                            SpecName = this.DataFile.TypeName,
                            TotalArea = DataFile.Area,//总面积
                            TotalLeftArea = DataFile.LeftArea,
                            TotalRightArea = DataFile.RightArea,
                            MeasureArea = DataFile.MeasureArea,
                            //AreaPercent = Math.Abs(Math.Round(((DataFile.MeasureArea - DataFile.Area) / DataFile.Area) * 100F, 2)),
                            AreaPercent = _data8(),
                            Data8 = _data8(),
                            MeasureLeftArea = DataFile.MeasureLeftArea,
                            MeasureRightArea = DataFile.MeasureRightArea,
                            DataFileJson = JsonSerializeHelper.SerializeObjectToJson(DataFile),

                            //BatchNo = UploadViewModel.CurrentUserChoicePlan.InspectModel.SERIAL_NUMBER
                            //valid
                            TotalWidth_Stable = _data10() + _data11(),// DataFile.StableKeys.LastOrDefault().Coordinate,
                            TotalWidth_Scan = _data14() + _data13(), //DataFile.MeasureKeys.LastOrDefault().Coordinate,
                            TotalWidth_Symmetry = _data18(),// Math.Abs(DataFile.XReference - Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.XReference)),
                                                            //valid
                            CrownWidth_Stable = _data25() + _data26(),// Math.Abs(DataFile.StableKeys[DataFile.StableKeys.Count - 2].Coordinate - DataFile.StableKeys[1].Coordinate),
                            CrownWidth_Scan = _data29() + _data30(),//Math.Abs(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.MeasureKeys[1].Coordinate),
                            CrownWidth_Symmetry = _data32(),//Math.Abs(Math.Abs(DataFile.XReference - DataFile.MeasureKeys[1].Coordinate) - (DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.XReference)),
                                                            //valid
                            ShoulderThickness_Stable = _data19() + _data20(),// DataFile.StableKeys[1].Value,
                            ShoulderThickness_ScanLeft = _data22(),// DataFile.MeasureKeys[1].Value,
                            ShoulderThickness_ScanRight = _data23(),//DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value,
                            ShoulderThickness_Symmetry = _data24(), //Math.Abs(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value - DataFile.MeasureKeys[1].Value),
                                                                    //valid
                            CrownThickness_Stable = _data27(), //IxReferenceStablePoint.Value,
                            CrownThickness_Scan = _data31(),//  IxReferenceMeasurePoint.Value,
                                                            //valid
                            BeadWingTipThickness_ScanLeft = _data40(),// DataFile.MeasureKeys.FirstOrDefault().Value,
                            BeadWingTipThickness_ScanRight = _data41(),//DataFile.MeasureKeys.LastOrDefault().Value,
                                                                       //valid
                                                                       //BeadWingWidth_Stable = Math.Abs(DataFile.StableKeys[1].Coordinate - DataFile.StableKeys[0].Coordinate),
                                                                       //BeadWingWidth_ScanLeft = Math.Abs(DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate),
                                                                       //BeadWingWidth_ScanRight = Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate),

                            BeadWingWidth_Symmetry = _data42(),// Math.Abs(Math.Abs(DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate) - Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate)),
                            Data9 = _data9(),
                            Data10 = _data10(),
                            Data11 = _data11(),
                            Data13 = _data13(),
                            Data14 = _data14(),
                            Data15 = _data15(),
                            Data18 = _data18(),
                            Data19 = _data19(),
                            Data20 = _data20(),
                            Data22 = _data22(),
                            Data23 = _data23(),
                            Data24 = _data24(),
                            Data25 = _data25(),
                            Data26 = _data26(),
                            Data27 = _data27(),
                            Data29 = _data29(),
                            Data30 = _data30(),
                            Data31 = _data31(),
                            Data32 = _data32(),
                            Data33 = _data33(),
                            Data34 = _data34(),
                            Data40 = _data40(),
                            Data41 = _data41(),
                            Data42 = _data42(),
                            Data45 = _data45(),
                            Data46 = _data46(),
                        };
                    }
                    else
                    {
                        // 弹出错误信息
                        MessageBox.Show("文件验证失败:\n" + string.Join("\n", errors), "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                // 记录错误日志
                Logger?.LogError(ex.Message, ex);
                MessageBox.Show("打开文件时出现错误: " + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        [RelayCommand]
        private void OpenReportData()
        {
            try
            {
                if (!isPrecheck())
                {
                    MessageBox.Show("请先执行本班次今日的班前检点！", "应用提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                string tempDir = TempDataSwapFolder;
                if (string.IsNullOrEmpty(tempDir))
                    tempDir = this.AppConfig.CurrentValue.Folder1Path;
                // 创建并配置 OpenFileDialog 对象
                var openFileDialog = new OpenFileDialog
                {
                    InitialDirectory = tempDir,
                    Title = "Open Text File",
                    Filter = "文本文件 (*.txt)|*.txt",
                    Multiselect = false
                };
                List<string> errors = null;
                // 显示文件选择对话框
                if (openFileDialog.ShowDialog() == true)
                {
                    string fileName = openFileDialog.FileName;
                    FileInfo fileInfo = new FileInfo(fileName);
                    TempDataSwapFolder = fileInfo.DirectoryName;

                    this.AppConfig.CurrentValue.Folder1Path = TempDataSwapFolder;
                    SaveNewJsonConfig();

                    // 加载并解析数据文件
                    this.DataFile = DataFileParser.LoadFromFile(fileName);

                    if (DataFile.Validate(out errors))
                    {
                        maySave = true;
                        //var IxReferenceStablePoint = DataFile.StableKeys.OrderBy(T => Math.Abs(T.Coordinate - DataFile.XReference)).FirstOrDefault();
                        //var IxReferencePointIndex = DataFile.StableKeys.IndexOf(IxReferenceStablePoint);
                        //var IxReferenceMeasurePoint = DataFile.MeasureKeys[IxReferencePointIndex];

                        //验证成功,赋值给本地视图模型
                        this.SemiSteelTreadScanReport = new();
                        SemiSteelTreadScanReport.PropertyChanged += SemiSteelTreadScanReport_PropertyChanged;


                        this.SemiSteelTreadScanReport.PlanId = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SERIAL_NUMBER;
                        this.SemiSteelTreadScanReport.Shift = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SHIFT;
                        this.SemiSteelTreadScanReport.SerialNumber = UploadViewModel.CurrentUserChoicePlan?.InspectModel.SERIAL_NUMBER;
                        this.SemiSteelTreadScanReport.ScanedDatetime = ScanDatetime;  //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        this.SemiSteelTreadScanReport.SpecNameInfact = UploadViewModel.CurrentUserChoicePlan?.InspectModel.PART_NUMBER;
                        this.SemiSteelTreadScanReport.PlanDate = UploadViewModel.CurrentUserChoicePlan.InspectModel.PLAN_DATE.Value;
                        this.SemiSteelTreadScanReport.Eqp = UploadViewModel.CurrentUserChoicePlan?.InspectModel.EQP;

                        this.SemiSteelTreadScanReport.SpecName = this.DataFile.TypeName;
                        this.SemiSteelTreadScanReport.TotalArea = DataFile.Area;//总面积
                        this.SemiSteelTreadScanReport.TotalLeftArea = DataFile.LeftArea;
                        this.SemiSteelTreadScanReport.TotalRightArea = DataFile.RightArea;
                        this.SemiSteelTreadScanReport.MeasureArea = DataFile.MeasureArea;
                        //AreaPercent = Math.Abs(Math.Round(((DataFile.MeasureArea - DataFile.Area) / DataFile.Area) * 100F, 2)),
                        this.SemiSteelTreadScanReport.AreaPercent = _data8();
                        this.SemiSteelTreadScanReport.Data8 = _data8();
                        this.SemiSteelTreadScanReport.MeasureLeftArea = DataFile.MeasureLeftArea;
                        this.SemiSteelTreadScanReport.MeasureRightArea = DataFile.MeasureRightArea;
                        this.SemiSteelTreadScanReport.DataFileJson = JsonSerializeHelper.SerializeObjectToJson(DataFile);

                        //BatchNo = UploadViewModel.CurrentUserChoicePlan.InspectModel.SERIAL_NUMBER
                        //valid
                        this.SemiSteelTreadScanReport.TotalWidth_Stable = _data10() + _data11();// DataFile.StableKeys.LastOrDefault().Coordinate,
                        this.SemiSteelTreadScanReport.TotalWidth_Scan = _data14() + _data13(); //DataFile.MeasureKeys.LastOrDefault().Coordinate,
                        this.SemiSteelTreadScanReport.TotalWidth_Symmetry = _data18();// Math.Abs(DataFile.XReference - Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.XReference)),
                                                                                      //valid
                        this.SemiSteelTreadScanReport.CrownWidth_Stable = _data25() + _data26();// Math.Abs(DataFile.StableKeys[DataFile.StableKeys.Count - 2].Coordinate - DataFile.StableKeys[1].Coordinate),
                        this.SemiSteelTreadScanReport.CrownWidth_Scan = _data29() + _data30();//Math.Abs(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.MeasureKeys[1].Coordinate),
                        this.SemiSteelTreadScanReport.CrownWidth_Symmetry = _data32();//Math.Abs(Math.Abs(DataFile.XReference - DataFile.MeasureKeys[1].Coordinate) - (DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.XReference)),
                                                                                      //valid
                        this.SemiSteelTreadScanReport.ShoulderThickness_Stable = _data19() + _data20();// DataFile.StableKeys[1].Value,
                        this.SemiSteelTreadScanReport.ShoulderThickness_ScanLeft = _data22();// DataFile.MeasureKeys[1].Value,
                        this.SemiSteelTreadScanReport.ShoulderThickness_ScanRight = _data23();//DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value,
                        this.SemiSteelTreadScanReport.ShoulderThickness_Symmetry = _data24(); //Math.Abs(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value - DataFile.MeasureKeys[1].Value),
                                                                                              //valid
                        this.SemiSteelTreadScanReport.CrownThickness_Stable = _data27(); //IxReferenceStablePoint.Value,
                        this.SemiSteelTreadScanReport.CrownThickness_Scan = _data31();//  IxReferenceMeasurePoint.Value;
                                                                                      //valid
                        this.SemiSteelTreadScanReport.BeadWingTipThickness_ScanLeft = _data40();// DataFile.MeasureKeys.FirstOrDefault().Value;
                        this.SemiSteelTreadScanReport.BeadWingTipThickness_ScanRight = _data41();//DataFile.MeasureKeys.LastOrDefault().Value;
                                                                                                 //valid
                                                                                                 //BeadWingWidth_Stable = Math.Abs(DataFile.StableKeys[1].Coordinate - DataFile.StableKeys[0].Coordinate);
                                                                                                 //BeadWingWidth_ScanLeft = Math.Abs(DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate);
                                                                                                 //BeadWingWidth_ScanRight = Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate);

                        this.SemiSteelTreadScanReport.BeadWingWidth_Symmetry = _data42();// Math.Abs(Math.Abs(DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate) - Math.Abs(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate));
                        this.SemiSteelTreadScanReport.Data9 = _data9();
                        this.SemiSteelTreadScanReport.Data10 = _data10();
                        this.SemiSteelTreadScanReport.Data11 = _data11();
                        this.SemiSteelTreadScanReport.Data13 = _data13();
                        this.SemiSteelTreadScanReport.Data14 = _data14();
                        this.SemiSteelTreadScanReport.Data15 = _data15();
                        this.SemiSteelTreadScanReport.Data18 = _data18();
                        this.SemiSteelTreadScanReport.Data19 = _data19();
                        this.SemiSteelTreadScanReport.Data20 = _data20();
                        this.SemiSteelTreadScanReport.Data22 = _data22();
                        this.SemiSteelTreadScanReport.Data23 = _data23();
                        this.SemiSteelTreadScanReport.Data24 = _data24();
                        this.SemiSteelTreadScanReport.Data25 = _data25();
                        this.SemiSteelTreadScanReport.Data26 = _data26();
                        this.SemiSteelTreadScanReport.Data27 = _data27();
                        this.SemiSteelTreadScanReport.Data29 = _data29();
                        this.SemiSteelTreadScanReport.Data30 = _data30();
                        this.SemiSteelTreadScanReport.Data31 = _data31();
                        this.SemiSteelTreadScanReport.Data32 = _data32();
                        this.SemiSteelTreadScanReport.Data33 = _data33();
                        this.SemiSteelTreadScanReport.Data34 = _data34();
                        this.SemiSteelTreadScanReport.Data40 = _data40();
                        this.SemiSteelTreadScanReport.Data41 = _data41();
                        this.SemiSteelTreadScanReport.Data42 = _data42();
                        this.SemiSteelTreadScanReport.Data45 = _data45();
                        this.SemiSteelTreadScanReport.Data46 = _data46();

                    }
                    else
                    {
                        // 弹出错误信息
                        MessageBox.Show("文件验证失败:\n" + string.Join("\n", errors), "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                // 记录错误日志
                Logger?.LogError(ex.Message, ex);
                MessageBox.Show("打开文件时出现错误: " + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void SemiSteelTreadScanReport_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Data8" )
            {
                OnPropertyChanged(nameof(Data8TextColor)); // 触发颜色更新
            }
            
            if (e.PropertyName == "Data13")
            {
                OnPropertyChanged(nameof(Data13TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data14")
            {
                OnPropertyChanged(nameof(Data14TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data15")
            {
                OnPropertyChanged(nameof(Data15TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data22")
            {
                OnPropertyChanged(nameof(Data22TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data23")
            {
                OnPropertyChanged(nameof(Data23TextColor)); // 触发颜色更新
            }

            if (e.PropertyName == "Data29")
            {
                OnPropertyChanged(nameof(Data29TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data30")
            {
                OnPropertyChanged(nameof(Data30TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data31")
            {
                OnPropertyChanged(nameof(Data31TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data34")
            {
                OnPropertyChanged(nameof(Data34TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data18")
            {
                OnPropertyChanged(nameof(Data18TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data24")
            {
                OnPropertyChanged(nameof(Data24TextColor)); // 触发颜色更新
            }


            if (e.PropertyName == "Data32")
            {
                OnPropertyChanged(nameof(Data32TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data40")
            {
                OnPropertyChanged(nameof(Data40TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data41")
            {
                OnPropertyChanged(nameof(Data41TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data42")
            {
                OnPropertyChanged(nameof(Data42TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data45")
            {
                OnPropertyChanged(nameof(Data45TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data46")
            {
                OnPropertyChanged(nameof(Data46TextColor)); // 触发颜色更新
            }

            if (e.PropertyName == "Data51")
            {
                OnPropertyChanged(nameof(Data51TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "Data50")
            {
                OnPropertyChanged(nameof(Data50TextColor)); // 触发颜色更新
            }
            if (e.PropertyName == "ManuData34")
            {
                OnPropertyChanged(nameof(ManuData34FTextColor)); // 触发颜色更新
            }
        }


        /// <summary>
        /// 上传当前条码以及关联数据到远程数据库,同时记录到本地数据记录
        /// </summary>
        [RelayCommand]
        private void UploadCurrentData()
        {
            if (!maySave)
            {
                MessageBox.Show("请先选择扫描的文本文件进行解析", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (this.SemiSteelTreadScanReport is null)
            {
                MessageBox.Show("请上传报表数据进行解析", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (string.IsNullOrEmpty(this.UserId) || this.UserId.Trim().Length > 8)
            {
                MessageBox.Show("检测员ID不合法", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //此处用于同步到本地库
            //插入本地库
            //更新中间表状态
            this.SemiSteelTreadScanReport.UserId = this.UserId.ToString();
            this.SemiSteelTreadScanReport.Shift = this.CurrentShift;
            ///this.SemiSteelTreadScanReport.CompensationCoefficient = CompensationCoefficient;
            //SemiSteelTreadScanReport.Data34 = _data34(DataFile);

            /*
            this.SemiSteelTreadScanReport.CompensationCoefficient = this.CompensationCoefficient;
            this.SemiSteelTreadScanReport.AntennaAdhesiveSpec_TopWidth = this.AntennaAdhesiveSpec_TopWidth;
            this.SemiSteelTreadScanReport.AntennaAdhesiveSpec_BottomWidth = this.AntennaAdhesiveSpec_BottomWidth;

            this.SemiSteelTreadScanReport.AntennaAdhesiveSpec_Penetration = this.AntennaAdhesiveSpec_Penetration;
            this.SemiSteelTreadScanReport.OthoerPointsThickness_Scan = this.OthoerPointsThickness_Scan;
            this.SemiSteelTreadScanReport.OthoerPointsThickness_Stable = this.OthoerPointsThickness_Stable;
            this.SemiSteelTreadScanReport.CrossSectionShape = this.CrossSectionShape;
            */
            //var msg = "确实要上报数据！";// GetFormattedPropertyComments(this.SemiSteelTreadScanReport);

            var msg = PropertyNameConverter.GetFormattedPropertyComments_v2(this.SemiSteelTreadScanReport);

            if (MessageBox.Show(msg, "请确认上报数据", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (var scope = this.provider.CreateScope())
                {
                    var reportService = scope.ServiceProvider.GetService<ILocalReportService>();
                    var uploadViewModel = scope.ServiceProvider.GetService<QualityDataUploadViewModel>();
                    int ret = reportService.Add<SemiSteelTreadScanReport>(this.SemiSteelTreadScanReport, uploadViewModel.CurrentUserChoicePlan.InspectModel);

                    if (ret == 0)
                    {
                        MessageBox.Show("保存数据失败,请稍后重试");
                    }
                    else
                    {
                        //关闭窗体
                        this.CloseWindow?.Invoke();
                    }
                }
            }
        }
        /// <summary>
        /// 检查是否已做过班前检点。
        /// </summary>
        /// <returns>已做过，返回真</returns>
        public bool isPrecheck()
        {
            using var scope = this.provider.CreateScope();
            var reportService = scope.ServiceProvider.GetService<ILocalReportService>();
            var CurrentShift = AppConfig.CurrentValue.GetCurrentShift();
            var dt = AppConfig.CurrentValue.GetCurrentProcuceDate();
            return reportService.isCheck(CurrentShift, dt);
        }

        public void UpdateUserId(string text)
        {
            try
            {
                this.AppConfig.CurrentValue.UserId = text;
                SaveNewJsonConfig();
            }
            catch (Exception ex)
            {
                Logger?.LogError("保存用户ID失败", ex);
            }
        }
        internal void UpdateCurrentShift(string text)
        {
            try
            {
                this.AppConfig.CurrentValue.CurrentShift = text;
                SaveNewJsonConfig();
            }
            catch (Exception ex)
            {
                Logger?.LogError("保存当前班次失败！", ex);
            }
        }
        private void SaveNewJsonConfig()
        {
            try
            {
                const string configPath = "./Configs/";
                const string configFileName = "AppConfig.json";
                const string tempFileName = "AppConfig_temp.json";

                string configFullPath = Path.Combine(configPath, configFileName);
                string tempFullPath = Path.Combine(configPath, tempFileName);

                // 复制原始配置文件到临时文件
                File.Copy(configFullPath, tempFullPath, overwrite: true);
                var currentValue = this.AppConfig.CurrentValue.Clone();
                // 修改临时文件
                JsonObject appSetting;
                using (FileStream fs = new FileStream(tempFullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                {
                    appSetting = JsonNode.Parse(fs).AsObject();

                    // 将当前的 CurrentAppConfig 序列化为 JsonNode
                    JsonNode sourceJsonNode = JsonSerializer.SerializeToNode(currentValue);

                    // 替换 "AppConfig" 节点
                    appSetting["AppConfig"] = sourceJsonNode;

                    // 清空文件并重置位置
                    fs.SetLength(0);
                    fs.Position = 0;

                    var options = new JsonSerializerOptions
                    {
                        WriteIndented = true // 格式化输出
                    };
                    JsonSerializer.Serialize(fs, appSetting, options);
                }

                // 原子性地替换原始配置文件
                File.Replace(tempFullPath, configFullPath, null);
            }
            catch (Exception ex)
            {
                this.Logger.LogError("保存配置文件失败", ex);
            }
        }

        public string? AntennaAdhesiveSpec_Penetration { get; set; }
        public string? OthoerPointsThickness_Scan { get; set; }
        public string? OthoerPointsThickness_Stable { get; set; }
        public string? CrossSectionShape { get; set; }
        [ObservableProperty]
        private YB_LOT_INSPECT_Local _curentInspect;

        [ObservableProperty]
        private string _userId;

        [ObservableProperty]
        private float _antennaAdhesiveSpec_TopWidth;

        [ObservableProperty]
        private float _antennaAdhesiveSpec_BottomWidth;

        [ObservableProperty]
        private string _currentShift;
        /// <summary>
        /// 总面积%
        /// 实际是比例
        /// (总面积实测值-总面积标准值)/总面积标准值*100%
        /// </summary>
        private float _data8()
        {
            return (float)(Math.Round(((DataFile.MeasureArea - DataFile.Area) / DataFile.Area) * 100F, 2));
        }

        /// <summary>
        /// 总宽(mm)  左 标准
        /// TXT文档，（[Keys]下面最后一行的左边数字）/2
        ///
        /// </summary>
        private float _data9()
        {
            return (float)DataFile.StableKeys.LastOrDefault().Coordinate / 2;
        }
        /// <summary>
        /// 总宽(mm)  右 标准
        /// TXT文档，（[Keys] 下面最后一行的左边数字）/2
        /// </summary>
        private float _data10()
        {
            return (float)DataFile.StableKeys.LastOrDefault().Coordinate / 2;
        }
        /// <summary>
        /// 总宽(mm)    标准
        /// TXT文档，[Keys]下面最后一行的左边数字
        /// SemiSteelTreadScanReport.TotalWidth_Stable
        /// </summary>
        private float _data11()
        {
            return (float)DataFile.StableKeys.LastOrDefault().Coordinate;
        }


        /// <summary>
        /// 总宽(mm)  左 实测
        /// TXT文档，[Xreference]下数字-[MeasureKeys]第1行左边数字
        /// </summary>
        private float _data13()
        {
            return (float)(DataFile.XReference - DataFile.MeasureKeys.FirstOrDefault().Coordinate);
        }


        /// <summary>
        /// 总宽(mm)  右 实测
        /// TXT文档，[MeasureKeys]最后1行左边数字-[Xreference]下数字
        /// </summary>
        private float _data14()
        {
            return (float)(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.XReference);
        }


        /// <summary>
        /// 总宽(mm)    实测
        /// TXT文档，[MeasureKeys]下面最后一行的左边数字
        /// </summary>
        private float _data15()
        {
            return (float)DataFile.MeasureKeys.LastOrDefault().Coordinate;
        }

        /// <summary>
        /// 左右宽度差 取绝对值
        /// TXT文档，[XReference]下面第一行数字-（[MeasureKeys]下面最后一行的左边数字-[XReference]下面第一行数字）
        /// </summary>
        public float _data18()
        {
            return (float)Math.Abs(DataFile.XReference - (DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.XReference));
        }

        /// <summary>
        /// 肩厚（mm）  左 标准
        /// TXT文档，[Keys]下面第二行的右边数字
        /// </summary>
        private float _data19()
        {
            return (float)DataFile.StableKeys[1].Value;
        }
        /// <summary>
        /// 肩厚（mm）  左 实测
        /// 
        /// TXT文档，[MeasureKeys]下面第二行的右边数字
        /// </summary>
        private float _data22()
        {
            return (float)DataFile.MeasureKeys[1].Value;
        }

        /// <summary>
        /// 肩厚（mm）  右 标准
        /// TXT文档，[Keys]下面倒数第二行的右边数字
        /// </summary>
        private float _data20()
        {
            return (float)DataFile.StableKeys[DataFile.StableKeys.Count - 2].Value;
        }
        /// <summary>
        /// 肩厚（mm）  右 实测
        /// TXT文档，[MeasureKeys]下面倒数第二行的右边数字
        /// </summary>
        private float _data23()
        {
            return (float)DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value;
        }

        /// <summary>
        /// 左右肩厚差
        /// TXT文档，ABS([MeasureKeys]下面第二行的右边数字-[MeasureKeys]下面倒2行的右边数字)
        /// </summary>
        public float _data24()
        {
            return (float)Math.Abs(DataFile.MeasureKeys[1].Value - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Value);
        }

        //冠宽(mm)
        /// <summary>
        /// 冠宽(mm)  左 标准
        /// （TXT文档，[Keys]下面倒2行的左边数字-[Keys]下面第2行的左边数字）/2
        /// </summary>
        private float _data25()
        {
            return (float)(DataFile.StableKeys[DataFile.StableKeys.Count - 2].Coordinate - DataFile.StableKeys[1].Coordinate) / 2;
        }
        /// <summary>
        /// 冠宽(mm)  左 实测
        /// TXT文档，Xreference-MeasureKeys第二行左边数字
        /// </summary>
        private float _data29()
        {
            return (float)(DataFile.XReference - DataFile.MeasureKeys[1].Coordinate);
        }
        /// <summary>
        /// 冠宽(mm)  右 标准
        /// （TXT文档，[Keys]下面倒2行的左边数字-[Keys]下面第2行的左边数字）/2
        /// </summary>
        private float _data26()
        {
            return (float)(DataFile.StableKeys[DataFile.StableKeys.Count - 2].Coordinate - DataFile.StableKeys[1].Coordinate) / 2;
        }
        /// <summary>
        /// 冠宽(mm)  右 实测
        /// TXT文档，MeasureKeys倒数第二行左边数字-Xreference
        /// </summary>
        private float _data30()
        {
            return (float)(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.XReference);
        }

        /// <summary>
        /// 冠宽(mm)    标准
        /// 
        /// TXT文档，[Keys]下面倒2行的左边数字-[Keys]下面第2行的左边数字
        /// </summary>
        private float _data27()
        {
            return (float)(DataFile.StableKeys[DataFile.StableKeys.Count - 2].Coordinate - DataFile.StableKeys[1].Coordinate);
        }
        /// <summary>
        /// 冠宽(mm)     实测
        /// TXT文档，[MeasureKeys]下面倒2行的左边数字-[MeasureKeys]下面第2行的左边数字
        /// </summary>
        private float _data31()
        {
            return (float)(DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.MeasureKeys[1].Coordinate);
        }

        /// <summary>
        /// 左右冠宽差    实测
        /// TXT文档，（[XReference]下面第一行数字-[MeasureKeys]下面第2行的左边数字）-（[MeasureKeys]下面倒2行数字-[XReference]下面第一行数字）
        /// </summary>
        public float _data32()
        {
            return (float)Math.Abs((DataFile.XReference - DataFile.MeasureKeys[1].Coordinate) - (DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate - DataFile.XReference));
        }

        //冠厚(mm)
        /// <summary>
        /// 冠厚(mm)    标准
        /// TXT文档，（[Keys]有多少行数据-1）/2的行数的右边数字
        /// </summary>
        private float _data33()
        {
            var pos = (int)((DataFile.StableKeys.Count - 1) / 2);
            return (float)DataFile.StableKeys[pos].Value;
        }

        /// <summary>
        /// 冠厚    实测
        /// TXT文档，[MeasureKeys]中左边对应[XReference]数据的右边数字+员工选择补偿系数的数值
        /// </summary>
        public float _data34()
        {
            var val = 0.0f;
            if (DataFile == null) return 0.0f;
            foreach (var ss in DataFile.MeasureKeys)
            {
                if (ss.Coordinate == DataFile.XReference)
                {
                    val = (float)ss.Value;
                }
            }
            return val;// + CompensationCoefficient;
        }

        /// <summary>
        /// 断面形状    实测
        /// </summary>
        [ObservableProperty]
        private string _checkPoint36;

        /// <summary>
        /// 胎翼宽度(mm)  左  实测
        /// TXT文档，[MeasureKeys]下面第二行的左边数字-[MeasureKeys]下面第一行的左边数字
        /// </summary>
        private float _data40()
        {
            return (float)(DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate);
        }

        /// <summary>
        /// 胎翼宽度(mm)  右  实测
        /// TXT文档，[MeasureKeys]最后一行的左边数字-[MeasureKeys]倒2行的左边数字
        /// </summary>
        private float _data41()
        {
            return (float)(DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate);
        }

        /// <summary>
        /// 胎翼宽度(mm)  左右宽度差  实测
        /// TXT文档，（[MeasureKeys]下面第二行的左边数字-[MeasureKeys]下面第一行的左边数字）-（[MeasureKeys]最后一行的左边数字-[MeasureKeys]倒2行的左边数字）
        /// </summary>
        public float _data42()
        {
            return (float)Math.Abs((DataFile.MeasureKeys[1].Coordinate - DataFile.MeasureKeys[0].Coordinate) - (DataFile.MeasureKeys.LastOrDefault().Coordinate - DataFile.MeasureKeys[DataFile.MeasureKeys.Count - 2].Coordinate));
        }


        /// <summary>
        /// 边缘端点厚度(mm)  左  实测
        /// TXT文档，[MeasureKeys]下面第一行的右边数字
        /// </summary>
        private float _data45()
        {
            return (float)DataFile.MeasureKeys[0].Value;
        }
        /// <summary>
        /// 边缘端点厚度(mm)  右  实测
        /// TXT文档，[MeasureKeys]下面最后一行的右边数字
        /// </summary>
        private float _data46()
        {
            return (float)DataFile.MeasureKeys.LastOrDefault().Value;
        }
        /*
        /// <summary>
        /// 天线胶形状、尺寸  天线胶上端宽度(mm)  实测
        /// 手工填写，数字，带1位小数
        /// </summary>
        private float _data50;

        /// <summary>
        /// 天线胶形状、尺寸  天线胶下端宽度(mm)  实测
        /// 手工填写，数字，带1位小数
        /// </summary>
        private float _data51;

        /// <summary>
        /// 天线胶形状、尺寸 天线胶贯通  实测
        /// </summary>
        [ObservableProperty]
        private string _checkPoint52;

        /// <summary>
        /// 其它点厚度(mm) 标准
        /// </summary>
        [ObservableProperty]
        private string _checkPoint53;
        /// <summary>
        /// 其它点厚度(mm) 实测
        /// </summary>
        [ObservableProperty]
        private string _checkPoint54;

        /// <summary>
        /// 判定 55
        /// </summary>
        [ObservableProperty]
        private string _passStatus = "True";

        /// <summary>
        /// MAX基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData30D;
        /// <summary>
        /// MAX基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData30E;
        /// <summary>
        /// MAX基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData30F;

        /// <summary>
        /// MIN基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData31D;
        /// <summary>
        /// MIN基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData31E;
        /// <summary>
        /// MIN基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData31F;

        /// <summary>
        /// 基部胶厚度差  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData32D;
        /// <summary>
        /// 基部胶厚度差  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData32E;
        /// <summary>
        /// 基部胶厚度差  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData32F;

        /// <summary>
        /// 胎面基部胶最小厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData33D;
        /// <summary>
        /// 胎面基部胶最小厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData33E;
        /// <summary>
        /// 胎面基部胶最小厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData33F;

        /// <summary>
        /// TUC差级ⅠA-BⅠ(mm)  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData34F;

        /// <summary>
        /// 备注
        /// </summary>
        [ObservableProperty]
        private string _remark;
        */


        public Brush Data8TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = 3;
                var lv = -3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data8, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data13TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data9 + 3;
                var lv = SemiSteelTreadScanReport.Data9 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data13, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        /// <summary>
        /// Data13TextColor Data14TextColor Data15TextColor Data22TextColor Data23TextColor
        /// </summary>
        public Brush Data14TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data10 + 3;
                var lv = SemiSteelTreadScanReport.Data10 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data14, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data15TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data11 + 3;
                var lv = SemiSteelTreadScanReport.Data11 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data15, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data22TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data19 + 0.3;
                var lv = SemiSteelTreadScanReport.Data19 - 0.3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data22, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data23TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data20 + 0.3;
                var lv = SemiSteelTreadScanReport.Data20 - 0.3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data23, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        /// <summary>
        /// Data29TextColor Data30TextColor Data31TextColor Data34TextColor Data18TextColor  Data24TextColor 
        /// </summary>
        public Brush Data29TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data25 + 3;
                var lv = SemiSteelTreadScanReport.Data25 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data29, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data30TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data26 + 3;
                var lv = SemiSteelTreadScanReport.Data26 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data30, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }

        public Brush Data31TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data27 + 3;
                var lv = SemiSteelTreadScanReport.Data27 - 3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data31, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }

        public Brush Data34TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = SemiSteelTreadScanReport.Data33 + 0.3;
                var lv = SemiSteelTreadScanReport.Data33 - 0.3;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data34, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data18TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 2;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data18, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data24TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 0.3;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data24, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        /// <summary>
        /// Data32TextColor Data40TextColor Data41TextColor Data42TextColor Data45TextColor Data46TextColor
        /// </summary>
        public Brush Data32TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 2;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data32, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data40TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 5.0;
                var rs = util.moreCheck(SemiSteelTreadScanReport.Data40, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data41TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 5.0;
                var rs = util.moreCheck(SemiSteelTreadScanReport.Data41, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data42TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 2;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data42, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data45TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 0.8;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data45, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data46TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 0.8;
                var rs = util.lessCheck(SemiSteelTreadScanReport.Data46, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        /// <summary>
        /// Data50TextColor Data51TextColor 
        /// </summary>
        public Brush Data50TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = 2 + 1;
                var lv = 2 - 1;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data50, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush Data51TextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;

                var hv = 4 + 2;
                var lv = 4 - 2;
                var rs = util.exeCheck(SemiSteelTreadScanReport.Data51, hv, lv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        public Brush ManuData34FTextColor
        {
            get
            {
                if (SemiSteelTreadScanReport == null)
                    return Brushes.Black;
                var hv = 5;
                var rs = util.lessCheck(SemiSteelTreadScanReport.ManuData34F, hv);
                return rs ? Brushes.Black : Brushes.Red;
            }
        }
        
        Util util = new Util();
    }
}
